#include <QFileDialog>
#include <QGraphicsScene>
#include<QDebug>
#include<opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>
#include "mainwindow.h"
#include "ui_mainwindow.h"

using namespace  cv;
using namespace std;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    inputscene = new QGraphicsScene(ui->InputGraphic);
    outputscene = new QGraphicsScene(ui->OutputGraphic);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_actionOpenImg_triggered()
{
    QString filename = QFileDialog::getOpenFileName
            (this,tr("Open File"),".",tr("Image Files (*.jpg *.bmp *.jpeg *.png)"));

    qDebug()<<filename<<endl;
    string fielnamepath=string(filename.toLocal8Bit());

    cout<< fielnamepath<<endl;
    image = cv::imread(fielnamepath);


    QImage img = QImage(image.data,image.cols,image.rows,image.step,QImage::Format_RGB888).rgbSwapped();
    inputscene->clear();
    inputscene->addPixmap(QPixmap::fromImage(img));
    ui->InputGraphic->setScene(inputscene);

//    cv::imshow("Open Image",image);
}
